<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:pou="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>GTWorld</title>
        <link href='resources/icon/map_blue.png' rel='shortcut icon' 
              type='image/png'/>
        <h:outputStylesheet name="css/menu.css"/>
        <h:outputStylesheet name="css/icon.css"/>
        <script src="http://maps.google.com/maps/api/js?sensor=true "   	
        type="text/javascript"></script>
        <script type="text/javascript">
            var currentMarker = null;  
      
            function handlePointClick(event) {  
                if(currentMarker == null) {  
                    document.getElementById('lat').value = event.latLng.lat();  
                    document.getElementById('lng').value = event.latLng.lng();  
  
                    currentMarker = new google.maps.Marker({  
                        position:new google.maps.LatLng(event.latLng.lat(), event.latLng.lng())  
                    });  
                              
                    gmap.addOverlay(currentMarker);
                    newPoi.show();
                }     
            }  
            
            function markerAddComplete() {  
  
                currentMarker = null;  
                newPoi.hide();  
            }
            
            function cancel() {  
                newPoi.hide();  
                currentMarker.setMap(null);  
                currentMarker = null;  
  
                return false;  
            }  
            
            function findMe() {
                navigator.geolocation.getCurrentPosition(
                function(position) {
                    var map = gmap.getMap(),
                    latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

                    map.setCenter(latlng);

                    var marker = new google.maps.Marker({
                        position: latlng, title:"¡Estas Aquí!"
                    });

                    marker.setMap(map);
                },
                function(error) {
                    alert(error.message);
                },
                {
                    enableHighAccuracy: true
                });
            }
            function handleDrop(event, ui) {
                ui.draggable.fadeOut('fast');		
            }

        </script>
    </h:head>
    <h:body onload="#{sessionController.checkLogout()}; #{sessionController.loadVisits()}; #{sessionController.loadNotificactions()}">
        <h:form>
            <pou:commandLink ajax="false" title="Home" update=":currentUI"
                             actionListener="#{sessionController.updateUI}">
                <pou:graphicImage value="resources/img/logo_gtworld.png" 
                                  style="margin-left: 100px; margin-top: 20px"/>
                <f:attribute name="uiName" value="home/main" />
            </pou:commandLink>

            <pou:menubar style=" display: inline-table; 
                         float: right; margin-right: 50px; margin-top: 20px">
                <pou:submenu label="  Administración" icon="admin"
                             rendered="#{sessionController.user.tipoUsuario}">
                    <pou:menuitem value="Gestión de POIs" update=":currentUI" 
                                  actionListener="#{sessionController.updateUI}">
                        <f:attribute name="uiName" value="admin/pois" />
                    </pou:menuitem>
                    <pou:menuitem value="Gestión de Redes" update=":currentUI" 
                                  actionListener="#{sessionController.updateUI}">
                        <f:attribute name="uiName" value="admin/redes" />
                    </pou:menuitem>
                    <pou:menuitem value="Gestión de Usuarios" update=":currentUI"
                                  actionListener="#{sessionController.updateUI}">
                        <f:attribute name="uiName" value="admin/usuarios" />
                    </pou:menuitem>
                    <pou:menuitem value="Gestión Tipos de POIs" update=":currentUI"
                                  actionListener="#{sessionController.updateUI}">
                        <f:attribute name="uiName" value="admin/tipos_pois" />
                    </pou:menuitem>

                </pou:submenu>
                <pou:submenu label="  POIs" icon="pois">
                    <pou:menuitem value="Crear POI" update=":currentUI"
                                  actionListener="#{sessionController.updateUI}">
                        <f:attribute name="uiName" value="poi/crear_poi" />
                    </pou:menuitem>
                    <pou:menuitem value="Gestionar POIs" update=":currentUI"
                                  actionListener="#{sessionController.updateUI}">
                        <f:attribute name="uiName" value="poi/gestionar_poi" />
                    </pou:menuitem>

                </pou:submenu>
                <pou:submenu label="  Mapas" icon="maps">
                    <pou:menuitem value="Mi Mapa" update=":currentUI"
                                  actionListener="#{sessionController.updateUI}">
                        <f:setPropertyActionListener value="#{sessionController.user}" 
                                                     target="#{miMapaController.idUser}" />
                        <f:setPropertyActionListener value="#{sessionController.centerMap}" 
                                                     target="#{miMapaController.centerMap}" />
                        <f:attribute name="uiName" value="maps/mi_mapa" />
                    </pou:menuitem>
                    <pou:menuitem value="Mis Visitas" update=":currentUI"
                                  actionListener="#{sessionController.updateUI}">
                        <f:setPropertyActionListener value="#{sessionController.user}" 
                                                     target="#{misVisitasController.idUser}" />
                        <f:setPropertyActionListener value="#{sessionController.centerMap}" 
                                                     target="#{misVisitasController.centerMap}" />
                        <f:attribute name="uiName" value="maps/mis_visitas" />
                    </pou:menuitem>
                    <pou:menuitem value="Mi Red" update=":currentUI"
                                  actionListener="#{sessionController.updateUI}">
                        <f:setPropertyActionListener value="#{sessionController.user}" 
                                                     target="#{misRedesController.idUser}" />
                        <f:setPropertyActionListener value="#{sessionController.centerMap}" 
                                                     target="#{misRedesController.centerMap}" />

                        <f:attribute name="uiName" value="maps/mis_redes" />
                    </pou:menuitem>

                </pou:submenu>
                <pou:submenu label="  Mi Red" icon="red">
                    <pou:menuitem value="Crear Red" update=":currentUI"
                                  action="#{redController.prepareCreate}"
                                  actionListener="#{sessionController.updateUI}">
                        <f:setPropertyActionListener value="#{sessionController.user}" 
                                                     target="#{redController.actual}" /> 
                        <f:attribute name="uiName" value="red/crear_red" />
                    </pou:menuitem>
                    <pou:menuitem value="Gestionar Redes" update=":currentUI"
                                  action="#{redController.prepareCreate}"
                                  actionListener="#{sessionController.updateUI}">
                        <f:setPropertyActionListener value="#{sessionController.user}" 
                                                     target="#{redController.actual}" />
                        <f:attribute name="uiName" value="red/gestionar_redes" />
                    </pou:menuitem>
                    <pou:menuitem value="Gestionar Miembros" update=":currentUI"
                                  action="#{redController.reset}"
                                  actionListener="#{sessionController.updateUI}">
                        <f:setPropertyActionListener value="#{sessionController.user}" 
                                                     target="#{redController.actual}" />
                        <f:attribute name="uiName" value="red/gestionar_miembros" />
                    </pou:menuitem>

                </pou:submenu>
                <pou:submenu label="  #{sessionController.user.nombreUsuario}"
                             icon="user">
                    <pou:menuitem value="Mi Cuenta" update=":currentUI"
                                  actionListener="#{sessionController.updateUI}">
                        <f:attribute name="uiName" value="user/cuenta" />
                    </pou:menuitem>
                    <pou:menuitem value="Notificaciones" update=":currentUI"
                                  actionListener="#{sessionController.updateUI}">
                        <f:attribute name="uiName" value="user/notificaciones" />
                    </pou:menuitem>
                    <pou:menuitem value="Salir" 
                                  actionListener="#{sessionController.logout}">
                        <f:setPropertyActionListener value="#{null}" 
                                                     target="#{redController.pagination}" /> 
                    </pou:menuitem>
                </pou:submenu>
            </pou:menubar>
        </h:form>
        <pou:separator style="margin-left: 50px; margin-right: 50px"/>


        <h:form id="currentUI" style="min-height: 500px; margin-left: 50px; 
                margin-right: 50px; margin-top: 10px" enctype="multipart/form-data">
            <ui:include src="#{sessionController.currentUI}" />
            <pou:growl id="messages"/>
        </h:form>

        <pou:separator style="margin-left: 50px; margin-right: 50px"/>

        <h:form>
            <h:outputLabel value="GTWorld® All Rights Reserved 2012" 
                           style="font-size: 10px; margin-left: 40%; font-family: verdana" />
            <pou:commandLink ajax="false" title="Fan Page" target="blank"
                             actionListener="#{sessionController.goFb}"
                             style="margin-left: 100px">
                <pou:graphicImage value="resources/img/facebook.png"/>
            </pou:commandLink>
            <pou:commandLink ajax="false" title="Follow Us" target="blank"
                             actionListener="#{sessionController.goTwitter}"
                             style="margin-left: 10px">
                <pou:graphicImage value="resources/img/twitter.png"/>
            </pou:commandLink>
            <pou:commandLink ajax="false" title="Ayuda" target="blank"
                             actionListener="#{sessionController.goHelp}"
                             style="margin-left: 25px">
                <pou:graphicImage value="resources/img/help.png"/>
            </pou:commandLink>
        </h:form>

        <ui:include src="UI/dialog/gallery.xhtml" />
        <ui:include src="UI/dialog/poi_map.xhtml" />
        <ui:include src="UI/dialog/confirm_delete_poi.xhtml" />
        <ui:include src="UI/dialog/new_tipo_poi.xhtml" />
        <ui:include src="UI/dialog/new_poi.xhtml" />
        <ui:include src="UI/dialog/info_poi.xhtml" />
        <ui:include src="UI/dialog/gallery_1.xhtml" />
        <ui:include src="UI/dialog/poi_map_1.xhtml" />
        <ui:include src="UI/dialog/confirm_delete_poi_1.xhtml" />
        <ui:include src="UI/dialog/info_poi_1.xhtml" />
        <ui:include src="UI/dialog/red_baja.xhtml" />
        <ui:include src="UI/dialog/red_edit.xhtml" />
        <ui:include src="UI/dialog/red_info.xhtml" />
        <ui:include src="UI/dialog/red_user.xhtml" />
        <ui:include src="UI/dialog/member_detail.xhtml" />
    </h:body>
</html>